package Demo;

import java.io.*;

public class Test2 {
    //根据字符流创建
    public static void main(String[] args) {
        Writer writer=null;
        try{
            writer=new FileWriter("C:\\java2024\\20241127\\test2.txt");
            writer.write(String.valueOf(123));
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(writer!=null){
                try{
                    writer.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
        Reader reader=null;
        try{
            reader=new FileReader("C:\\java2024\\20241127\\test2.txt");
            int num;
            while((num=reader.read())!=-1){
                System.out.println((char)num);//不加char打印的是1,2,3的Ascall码值
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(reader!=null){
                try{
                    reader.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
